package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("listInventory")
    public Map<String,Object> getListInventory(Integer page, Integer rows, String codeOrName, Integer goodsTypeId){
        //Integer page, Integer rows, String codeOrName, Integer goodsTypeId
        Map<String,Object> map = new HashMap<>();
        map = goodsService.getListInventory(page,rows,codeOrName,goodsTypeId);
        return map;
    }

    @PostMapping("/list")
    public Map<String, Object> getGoodsList(Integer page, Integer rows, String goodsName, Integer goodsTypeId) {
        Map<String, Object> goodsList = goodsService.getGoodsList(page, rows, goodsName, goodsTypeId);
        return goodsList;
    }

    @PostMapping("getNoInventoryQuantity")
    public Map<String, Object> getNoInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        Map<String, Object> noGoodsList = goodsService.getNoInventoryQuantity(page, rows, nameOrCode);
        return noGoodsList;
    }

    @PostMapping("getHasInventoryQuantity")
    public Map<String, Object> getHasInventoryQuantity(Integer page, Integer rows, String nameOrCode) {
        Map<String, Object> hasGoodsList = goodsService.getHasInventoryQuantity(page, rows, nameOrCode);
        return hasGoodsList;
    }

    @PostMapping("saveStock")
    public ServiceVO saveStock(Integer goodsId, Integer inventoryQuantity, double purchasingPrice) {
        goodsService.saveStock(goodsId, inventoryQuantity, purchasingPrice);
        return new ServiceVO(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS, null);
    }

    @PostMapping("deleteStock")
    public ServiceVO deleteStock(Integer goodsId){
        goodsService.deleteStock(goodsId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
    }

    @PostMapping("listAlarm")
    public Map<String,Object> listAlarm(){
        Map<String,Object> map  = goodsService.getGoodsAlarmList();
        return map;
    }

}
